<?php

namespace App\Models;

use App\Models\Traits\BelongsToApplication;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use BelongsToApplication,
        HasDateTimeFormatter,
        HasApiTokens;

    protected $guarded = [];

    protected $casts = [
        'lock' => 'bool',
    ];

    public function wechat(): BelongsTo
    {
        return $this->belongsTo(Wechat::class);
    }

    public function orders(): HasMany
    {
        return $this->hasMany(Order::class);
    }

    public function players(): BelongsToMany
    {
        return $this->belongsToMany(Player::class, 'user_player')
            ->withPivot('guardian');
    }
}
